package com.example.poemtest.mine;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.example.poemtest.R;
import com.example.poemtest.utils.DataCleanManagerUtils;
import com.example.poemtest.utils.FullScreenUtil;

/**
 * 通用设置页面
 */
public class UniversalSetupActivity extends AppCompatActivity implements View.OnClickListener {

    //属性
    private ImageView back;
    private LinearLayout delete;
    private Switch speak;
    private TextView tvCache;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FullScreenUtil.getInstance().fullScreen(this,true);
        setContentView(R.layout.activity_universal_setup);
        //绑定控件对象
        initData();
    }

    /**
     * 绑定控件对象
     */
    private void initData() {
        back = findViewById(R.id.back_to_setup);
        back.setOnClickListener(this);
        speak = findViewById(R.id.speak);
        speak.setOnClickListener(this);
        delete = findViewById(R.id.delete);
        delete.setOnClickListener(this);
        tvCache = findViewById(R.id.tv_cache);
        String size = DataCleanManagerUtils.getTotalCacheSize(this);
        tvCache.setText(size);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_to_setup:
                //点击返回到设置页面
                Intent intent = new Intent(this, SetupActivity.class);
                startActivity(intent);
                break;
            case R.id.speak:
                //点击语音播报按钮

                break;
            case R.id.delete:
                //点击一键清除缓存按钮
                DataCleanManagerUtils.clearAllCache(this);
                tvCache.setText(DataCleanManagerUtils.getTotalCacheSize(UniversalSetupActivity.this));
                Toast.makeText(this, "清除缓存成功", Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
        }
    }
}